<?php
class CmsPhotosControl extends CmsBaseControl
{
    protected $templateFile = 'CmsPhotos';

    public function Render()
    {
        BaseConfig::GetInstance()->AddCss('upload/uploadify');
        BaseConfig::GetInstance()->AddSharedJs('upload/uploadify, upload/swfobject');
        GridConfig::GetInstance()->AddSharedJs('GridControl, GridSelectControl');
        CmsConfig::GetInstance()->AddSharedJs('CmsPhotoListControl');
        CmsConfig::GetInstance()->AddSharedJs('CmsPhotoEditControl');

        $l = $this->GetListControl();
        $e = $this->GetEditControl();
        $u = $this->GetUploadControl();

        $this->Replace('list', $l->Render());
        $this->Replace('edit', $e->Render());
        $this->Replace('upload', $u->Render());
        $this->Replace('listName', $l->GetName());
        $this->Replace('editName', $e->GetName());
        $this->Replace('uploadName', $u->GetName());
        return parent::Render();
    }

    protected function GetListControl()
    {
        return new CmsPhotoListControl('CmsPhoto');
    }

    protected function GetEditControl()
    {
        return new CmsPhotoEditControl();
    }

    protected function GetUploadControl()
    {
        $u = new UploadControl($this->GetRefreshUrl());
        $u->AddParam('action', 'PhotoUpload');
        return $u;
    }

    public function PhotoUpload()
    {
        Photo::GetInstance()->SaveUploadedPhoto();
    }
}
?>
